package com.zyj.myapplication.Fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.zyj.myapplication.Adapter.ClassInfoAdapter;
import com.zyj.myapplication.Javabean.Club;
import com.zyj.myapplication.Model.ClubModel;
import com.zyj.myapplication.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class CClassFragment extends Fragment {
    private RecyclerView recyclerView;
    private Context mContext;
    private String club_id;
    private List<Club.ClubcourseEntity> Data;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_cclass, container, false);
        recyclerView = (RecyclerView) view.findViewById(R.id.classinfo_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局
        Intent intent = getActivity().getIntent();
        club_id = intent.getStringExtra("club_id");
        showData();
        return view;
    }

    private void showData() {
        ClubModel clubModel = new ClubModel();
        Call<Club> call = clubModel.getClubClass(club_id);
        call.enqueue(new Callback<Club>() {
            @Override
            public void onResponse(Call<Club> call, Response<Club> response) {
                Data = response.body().getClubcourse();
                recyclerView.setAdapter(new ClassInfoAdapter(getActivity(), Data));
            }

            @Override
            public void onFailure(Call<Club> call, Throwable t) {
                Toast.makeText(mContext, "获取失败", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
